package com.derek.omshopping.ui.classify;

import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.GridView;
import android.widget.ImageView;

import com.bumptech.glide.Glide;
import com.derek.omshopping.R;
import com.derek.omshopping.base.BaseFragment;
import com.derek.omshopping.bean.classify.ClassifyRightTypeBean;
import com.derek.omshopping.utils.MyGridView;

import java.util.List;

import zxing.android.CaptureActivity;

/**
 * Created by My on 2016/10/19.
 */

public class ClassifyRightTypeFragment extends BaseFragment implements ClassifyRightTypeContract.View {
    private MyGridView gv;
    private ImageView iv;
    private String code_mgroup;
    private ClassifyRightTypePresenter presenter;


    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {

        View view=inflater.inflate(R.layout.fragment_classifyrighttype,null);
        gv= (MyGridView) view.findViewById(R.id.gv_classify_right);
        gv.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                Intent intent=new Intent(getActivity(), ClassifyDetailActivity.class);
                startActivity(intent);

            }
        });
        iv= (ImageView) view.findViewById(R.id.iv_classifyRightType);
        Bundle bundle=getArguments();
        if(bundle!=null){
            code_mgroup=bundle.getString("code_mgroup");
            Log.i("tag",code_mgroup+"<><><><><><><><><><><>");
        }
        presenter=new ClassifyRightTypePresenter(this);
        presenter.getRightTypeFromNet(code_mgroup);

        return view;
    }

    @Override
    protected void initData() {


    }

    @Override
    protected void initView() {

    }

    @Override
    public int getLayoutId() {
        return R.layout.fragment_classifyrighttype;
    }

    @Override
    public void onRigthTypeSuccess(List<ClassifyRightTypeBean> list_right,String tag_img_path) {
        Glide.with(getActivity()).load(tag_img_path).placeholder(R.mipmap.meiri_logo).crossFade().into(iv);
        ClassifyRightTypeAdapter classifyRightTypeAdapter=new ClassifyRightTypeAdapter(list_right,getActivity());
        gv.setAdapter(classifyRightTypeAdapter);
    }

    @Override
    public void onRigthTypeFail(String msg) {

    }
}
